const question = require("../models/question")

var express = require('express');
var router = express.Router();

const formidable = require('formidable');

//返回图片
router.post('/', (req, res, next) => {
    var form = new formidable.IncomingForm();
    form.parse(req, async function (err, fields, files) {
        if (err) {
            res.json({ 'state': false, 'msg': err })
        } else {
            try{
                  let docs = await question.find({
                    point_id: fields.point_id
                  })  
                  if(docs.length!==0){
                    docs = docs.map(item => {
                          item.answer = [];
                          item.illustrationContent = '';
                          return item
                      })
                  }
                //   console.log(docs)
                  res.json({
                      'state': true,
                      'result': docs
                  })
            } catch(err) {
                // console.log(err)
                res.json({
                    'state': false,
                    'msg': err
                })
            }
        }
    });

});

module.exports = router;